import Vue from 'vue'  //因为要用vue.use要引入vue
import Router from 'vue-router' //引入路由
// import HelloWorld from '@/components/HelloWorld'
//导入组件
// import home from '../components/home.vue'
// import about from '../components/about.vue'
// import user from '../components/user.vue'
//通过Vue.use(插件)传入我们的路由插件，不管是什么插件以后都是这么传入的
Vue.use(Router)
const HelloWorld = () => import('@/components/HelloWorld')
const home = () => import('../components/home.vue')
const about = () => import('../components/about.vue')
const user = () => import('../components/user.vue')
const news = () => import('../components/homenews.vue')
const message = () => import('../components/homemessage.vue')
const profile = () => import('../components/Profile.vue')
//创建路由对象
const routes = [ //数组，配置路由和组件之间的关系，可以写出去
  {
    path: '/', //组件路径
    //redirect: '/home', //重定向到'home' 那就是网站页面是'/'路径也会更改为'/home'
    component: HelloWorld //
  },
  {
    path: '/home',
    component: home,
    meta: {
      title: '首页'
    },
    children: [
      // {
      //   path: '',
      //   redirect: 'news'
      // },
      {
        path: 'news',
        meta: {
          title: '首页新闻'
        },
        component: news
      },
      {
        path: 'message',
        meta: {
          title: '首页信息'
        },
        component: message
      }
    ]
  },
  {
    path: '/about', //
    meta: {
      title: '关于'
    },
    component: about //
  },
  {
    path: '/user/:userId',
    meta: {
      title: '用户'
    },
    component: user
  },
  {
    path: '/profile',
    meta: {
      title: '档案'
    },
    component: profile,
  }
]
const router = new Router({ //导出这个对象
  routes, //传入router
  mode: 'history'
})
router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})
export default router